{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Pandas CSV 文件\n",
    "# \n",
    "import pandas as pd\n",
    "\n",
    "df = pd.read_csv('../../data/nba.csv')\n",
    "print(df.to_string())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# to_csv\n",
    "# \n",
    "import pandas as pd\n",
    "\n",
    "# 三个字段 name, site, age\n",
    "nme = [\"Google\", \"Runoob\", \"Taobao\", \"Wiki\"]\n",
    "st = [\"www.google.com\", \"www.runoob.com\",\n",
    "      \"www.taobao.com\", \"www.wikipedia.org\"]\n",
    "ag = [90, 40, 80, 98]\n",
    "\n",
    "# 字典\n",
    "dict = {'name': nme, 'site': st, 'age': ag}\n",
    "df = pd.DataFrame(dict)\n",
    "print(df)\n",
    "\n",
    "# 保存 dataframe\n",
    "df.to_csv('./site.csv')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 458 entries, 0 to 457\n",
      "Data columns (total 9 columns):\n",
      " #   Column    Non-Null Count  Dtype  \n",
      "---  ------    --------------  -----  \n",
      " 0   Name      457 non-null    object \n",
      " 1   Team      457 non-null    object \n",
      " 2   Number    457 non-null    float64\n",
      " 3   Position  457 non-null    object \n",
      " 4   Age       457 non-null    float64\n",
      " 5   Height    457 non-null    object \n",
      " 6   Weight    457 non-null    float64\n",
      " 7   College   373 non-null    object \n",
      " 8   Salary    446 non-null    float64\n",
      "dtypes: float64(4), object(5)\n",
      "memory usage: 32.3+ KB\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "# 数据处理\n",
    "# \n",
    "import pandas as pd\n",
    "\n",
    "# head( n ) 方法用于读取前面的 n 行，如果不填参数 n ，默认返回 5 行。\n",
    "df = pd.read_csv('../../data/nba.csv')\n",
    "# print(df.head())\n",
    "\n",
    "# tail( n ) 方法用于读取尾部的 n 行，如果不填参数 n ，默认返回 5 行，空行各个字段的值返回 NaN。\n",
    "# print(df.tail())\n",
    "\n",
    "# info() 方法返回表格的一些基本信息：\n",
    "print(df.info())\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.9 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.9"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "cf18841ace8313d0bc088ca146c17a6c0040e82121d5cb75c0ea07172309253d"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
